import useAntdList from "@/hooks/useAntdList"
import useAntdModal, { AntdModalProps } from "@/hooks/useAntdModal"
import { queryApps, saveReleasePlan } from "@/service/deliver"
import { Button, DatePicker, Form, Input, Modal, Table } from "antd"
import CreateAppVersion from "../CreateAppVersion"

const LinkApp = ({ form, closeModal, refresh, modalProps }: AntdModalProps) => {
 const {tableProps} =   useAntdList(queryApps,{})
const createAppVersion =  useAntdModal({refresh})
  const onOk = async () => {
    let data = await form.validateFields()
    data.startDate = data.date[0].format('YYYY-MM-DD HH:mm:ss');
    data.endDate = data.date[1].format('YYYY-MM-DD HH:mm:ss');
    delete data.date
    await saveReleasePlan(data)
    refresh()
    closeModal()
  }
  const columns = [
    {
        title:'名称',
        dataIndex:'name'
    },
    {
        title:'操作',
        render(_){
            return <Button type='link' onClick={()=>createAppVersion.openModal({..._})}>关联</Button>
        }
        // dataIndex:'name'
    }
  ]
  return <Modal title='关联APP'  {...modalProps} onOk={onOk}>
    <CreateAppVersion {...createAppVersion}/>
     <Table  {...tableProps} columns={columns}/>
  </Modal>
}
export default LinkApp